﻿using System;
using AMM.Model;
using AMM.Model.Store;

namespace AMM.UserControls {
    public partial class OutStoreOrderSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int inStoreTypeValue = Convert.ToInt32(this.cmbOutStoreType.SelectedValue);

            OutStoreOrderSearchModel searchResult = new OutStoreOrderSearchModel();
            searchResult.OutStoreOrderCode = this.tbProduceConductCode.Text;
            searchResult.MaterialCode = this.tbMaterialCode.Text;
            searchResult.ProduceConductCode = this.tbProduceConductCode.Text;
            searchResult.OutStoreDateStart = this.GetDateTimePickerValue(this.dtpOutStoreDateStart);
            searchResult.OutStoreDateEnd = this.GetDateTimePickerValue(this.dtpOutStoreDateEnd);
            searchResult.MaterialOutStoreTypeId = inStoreTypeValue;

            if (inStoreTypeValue == 0) { searchResult.MaterialOutStoreTypeId = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbProduceConductCode.Clear();
            this.tbMaterialCode.Clear();
            this.tbOutStoreOrderCode.Clear();
            this.dtpOutStoreDateStart.Checked = false;
            this.dtpOutStoreDateEnd.Checked = false;
            this.cmbOutStoreType.SelectedIndex = 0;
        }

        public OutStoreOrderSearchControl() {
            this.InitializeComponent();
        }

        private void OutStoreOrderSearchControl_Load(object sender, EventArgs e) {
            this.BindBasics(this.cmbOutStoreType, Business.BasicsType.MaterialOutStoreType);
        }
    }
}
